# See LICENSE file for copyright and license details.

include config.mk

SRC = err.c list.c set.c map.c graph.c index.c trie.c acts.c state.c symbol.c
OBJ = $(SRC:.c=.o)

LIB = libnit.a
INC = err.h list.h set.h map.h graph.h dispose.h index.h trie.h acts.h \
	state.h symbol.h

PKG_STR = "\nIf this is a local install you may need to run:\n\t\
\"export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig\" \nto use this library.\n"

.PHONY: all install uninstall clean

all: $(LIB)

$(LIB): $(OBJ)
	@$(AR) -rcs $@ $(OBJ)

.c.o:
	@$(CC) $(CFLAGS) -c $<

install: $(LIB) $(INC)
	@echo @ install nit to $(DESTDIR)$(PREFIX)
	@mkdir -p $(DESTDIR)$(PREFIX)/lib
	@cp $(LIB) $(DESTDIR)$(PREFIX)/lib/$(LIB)
	@mkdir -p $(DESTDIR)$(PREFIX)/include/nit
	@cp $(INC) $(DESTDIR)$(PREFIX)/include/nit/
	@echo @ install nit.pc to $(PREFIX)
	@printf $(PKG_STR)
	@mkdir -p $(PREFIX)/lib/pkgconfig
	@cp nit.pc $(PREFIX)/lib/pkgconfig/

uninstall:
	@echo @ uninstall nit from $(DESTDIR)$(PREFIX)
	@rm -f $(DESTDIR)$(PREFIX)/lib/$(LIB)
	@rm -rf $(DESTDIR)$(PREFIX)/include/nit/
	@rm -f $(PREFIX)/lib/pkgconfig/nit.pc

clean:
	rm -f $(LIB) $(OBJ)
